Imports Microsoft.VisualBasic
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections.Generic
Imports EntityLayer

Public Class ProductoPostulanteDA


    Public Shared Function Agregar(ByVal ProductoPostulanteEN As ProductoPostulante) As Boolean
        Try
            Dim myConnection As New SqlConnection(ConexionDA.ObtenerCnx)
            Dim myCommand As New SqlCommand("usp_AddProductoPostulante", myConnection)
            myCommand.CommandType = CommandType.StoredProcedure

            Dim para As SqlParameter

            para = New SqlParameter("@strIdCarta", SqlDbType.VarChar, 5)
            para.Direction = ParameterDirection.Input
            para.Value = ProductoPostulanteEN.NumeroCarta
            myCommand.Parameters.Add(para)

            para = New SqlParameter("@strIdProducto", SqlDbType.VarChar, 5)
            para.Direction = ParameterDirection.Input
            para.Value = ProductoPostulanteEN.CodigoProducto
            myCommand.Parameters.Add(para)

            para = New SqlParameter("@strNombreProducto", SqlDbType.VarChar, 100)
            para.Direction = ParameterDirection.Input
            para.Value = ProductoPostulanteEN.NombreProducto
            myCommand.Parameters.Add(para)

            myConnection.Open()
            myCommand.ExecuteNonQuery()
            myConnection.Close()

            Return True
        Catch ex As Exception
            Dim E As String = ex.Message
            Return False
        End Try

    End Function

    Public Shared Function ListarProductosAsignados(ByVal strIdCarta As String) As DataSet
        Dim myConnection As New SqlConnection(ConexionDA.ObtenerCnx)
        Dim myDataadapter As New SqlDataAdapter("usp_ListProductosAsignados", myConnection)
        myDataadapter.SelectCommand.CommandType = CommandType.StoredProcedure

        Dim ds As New DataSet

        Dim para As SqlParameter

        para = New SqlParameter("@strIdCarta", SqlDbType.VarChar, 5)
        para.Direction = ParameterDirection.Input
        para.Value = strIdCarta
        myDataadapter.SelectCommand.Parameters.Add(para)

        myDataadapter.Fill(ds, "Productos")

        Return ds
    End Function

    Public Shared Function Eliminar(ByVal strIdCarta As String, ByVal strIdProducto As String) As Boolean
        Try
            Dim myConnection As New SqlConnection(ConexionDA.ObtenerCnx)
            Dim myCommand As New SqlCommand("usp_DelProductoPostulante", myConnection)
            myCommand.CommandType = CommandType.StoredProcedure

            Dim para As SqlParameter

            para = New SqlParameter("@strIdCarta", SqlDbType.VarChar, 5)
            para.Direction = ParameterDirection.Input
            para.Value = strIdCarta
            myCommand.Parameters.Add(para)

            para = New SqlParameter("@strIdProducto", SqlDbType.VarChar, 5)
            para.Direction = ParameterDirection.Input
            para.Value = strIdProducto
            myCommand.Parameters.Add(para)

            myConnection.Open()
            myCommand.ExecuteNonQuery()
            myConnection.Close()

            Return True
        Catch ex As Exception
            Dim E As String = ex.Message
            Return False
        End Try

    End Function


End Class
